function [output] = ge_grid(x_min,x_max,y_min,y_max, varargin )
% Reference page in help browser: 
% 
% <a href="matlab:web(fullfile(ge_root,'html','ge_grid.html'),'-helpbrowser')">link</a> to html documentation
% <a href="matlab:web(fullfile(ge_root,'html','license.html'),'-helpbrowser')">show license statement</a> 
%
  

AuthorizedOptions = authoptions( mfilename );



         %id = 'grid';
      idTag = 'id';
       %name = 'ge_grid';
 description = '';
 visibility = 1;
  lineColor = 'FF00FF00';
  polyColor = '00ffffff';
  lineWidth = 1.0;
    timeStamp = ' ';
timeSpanStart = ' ';
 timeSpanStop = ' ';
    snippet = ' ';
   altitude = 1.0;
   extrude = 1;
 altitudeMode = 'clampToGround';
    latRes = abs( y_max - y_min );
    lonRes = abs( x_min - x_max );
    tessellate = 1;
      region = ' ';


parsepairs %script that parses Parameter/Value pairs.

if( isempty( y_min ) || isempty( y_max ) || isempty( x_min ) || isempty( x_max) )
    error('empty coordinates passed to ge_grid(...).');
end

if ~(isequal(altitudeMode,'clampToGround')||...
   isequal(altitudeMode,'relativeToGround')||...
   isequal(altitudeMode,'absolute'))

    error(['Variable ',39,'altitudeMode',39, ' should be one of ' ,39,'clampToGround',39,', ',10,39,'relativeToGround',39,', or ',39,'absolute',39,'.' ])
    
end 


output= '';

col = y_min;
for row = (x_min):lonRes:(x_max-lonRes)
    output = [output, ge_box(row+lonRes,row,y_max,y_min,...
                                            'timeStamp',timeStamp,...
                                            'snippet', snippet,...
                                            'description', description,...
                                            'region', region, ...
                                        'timeSpanStart',timeSpanStart,...
                                         'timeSpanStop',timeSpanStop,...
                                             'altitude',altitude,...
                                           'tessellate',tessellate,...
                                         'altitudeMode',altitudeMode,...
                                              'extrude',extrude,...
                                                 'name',['gridcell_X=',num2str(col),';Y=',num2str(row)],...
                                            'lineWidth',lineWidth,...
                                            'lineColor',lineColor,...
                                            'polyColor',polyColor,...
                                           'visibility',visibility)];
end  

row = x_min;
for col = (y_min):latRes:(y_max-latRes)
    output = [output, ge_box(x_min,x_max,col+latRes,col,... 
                                            'timeStamp',timeStamp,...
                                            'snippet', snippet,...
                                            'description',description,...
                                        'timeSpanStart',timeSpanStart,... 
                                         'timeSpanStop',timeSpanStop,... 
                                             'altitude',altitude,... 
                                           'tessellate',tessellate,... 
                                         'altitudeMode',altitudeMode,... 
                                              'extrude',extrude,... 
                                                 'name',['gridcell_X=',num2str(col),';Y=',num2str(row)],... 
                                            'lineWidth',lineWidth,... 
                                            'lineColor',lineColor,...
                                            'polyColor',polyColor,... 
                                           'visibility',visibility)];
end
 
